package com.bdqn.controller;

import com.bdqn.mapper.HisRegistrationMapper;
import com.bdqn.pojo.HisRegistration;
import com.bdqn.service.HisRegistrationService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Random;

//挂号控制器
@RestController
@CrossOrigin
@RequestMapping("/HisRegistration")
public class HisRegistrationController {
    @Autowired
    HisRegistrationService hisRegistrationService;
    @GetMapping("getHisRegistration")//分页
//    int pageNum, int pageSize, int deptId, String patientName, int schedulingType, int subsectionType, int registrationStatus
    public PageInfo<HisRegistration> getHisRegistration(@RequestParam(value = "pageNum",defaultValue = "1",required = false) int pageNum,
                                                    @RequestParam(value = "pageSize",defaultValue = "5",required = false) int pageSize,
                                                    @RequestParam(value = "deptId",defaultValue = "0",required = false) int deptId,
                                                    @RequestParam(value = "patientName",defaultValue = "",required = false) String patientName,
                                                    @RequestParam(value = "schedulingType",defaultValue = "0",required = false) int schedulingType,
                                                    @RequestParam(value = "subsectionType",defaultValue = "0",required = false) int subsectionType,
                                                    @RequestParam(value = "registrationStatus",defaultValue = "6",required = false) int registrationStatus){
        PageInfo<HisRegistration> list=hisRegistrationService.getHisRegistrationFY(pageNum,pageSize,deptId,patientName,schedulingType,subsectionType,registrationStatus);
        return list;
    }
    //添加挂号
    @GetMapping("addHisRegistration")
    public String addHisRegistration(HisRegistration hisRegistration){
        System.out.println(hisRegistration);
        hisRegistration.setVisitDate(hisRegistration.getVisitDate().substring(0,10));
        Random random=new Random();
        String bianhao="";
        for (int i=1;i<=19;i++){
            bianhao+=random.nextInt(9)+1;
        }
        hisRegistration.setRegId(bianhao);//挂号流水赋值
        bianhao="";
        for (int i=1;i<=19;i++){
            bianhao+=random.nextInt(9)+1;
        }
        hisRegistration.setPatientId(bianhao);//患者 ID赋值
        int row =0;
        row=hisRegistrationService.addHisRegistration(hisRegistration);
        return bianhao;
    }
    @GetMapping("getHisRegistrationDANGE")
    public int getHisRegistrationDANGE(@RequestParam(value = "regStatus",defaultValue = "",required = false) int regStatus,
                                       @RequestParam(value = "regId",defaultValue = "",required = false) String regId){
        System.out.println(regStatus+"=="+regId);
        int row=0;
        row=hisRegistrationService.setHisRegistrationDANGE(regStatus,regId);
        System.out.println(row);
        return row;
    }
}
